﻿#!/usr/bin/env python
# -*- coding: utf-8 -*-
from DB.DB_Classes import *
from sets import Set
import os
import codecs
import datetime
import logging
from google.appengine.ext import ndb
#from mapreduce import operation as op

def format_hour(time):
    if time == " ":
        time = "---"
    else:
        time = time[:-2] +":"+ time[-2:]
    return time



def importer(uni = u"TAU", sem = u"20151"):
    
    complete_semester={}
    complete_semester_bid={}
    faculties_and_hugs = Set([])
    lecturers = Set([])
    courses_set = Set([])
    num_to_hug = {}
    main_course = {}
    sub_course = {}
    course_to_lec = {}
    excellence = {}
    
    fn = os.path.join(os.path.split(__file__)[0], 'Data_Dumps','TAU','Lecturers')
    for file1 in os.listdir(fn):
        with codecs.open(os.path.join(fn, file1), 'r',encoding = 'utf-8') as f:
            line = f.readline()
            lecs = line.split('~')
            for lec_1 in lecs:
                if lec_1 == "":
                    continue
                if file1[5:] == "rector.txt":
                    if excellence.get(lec_1) is None:
                        excellence[lec_1]= ["rec" + file1[:4] + "~",""]
                    else:
                        excellence[lec_1][0] = excellence[lec_1][0] + "rec" + file1[:4] + "~"
                else:
                    if excellence.get(lec_1) is None:
                        excellence[lec_1]= ["","best" + file1[:4] + "~"]
                    else:
                        excellence[lec_1][1] = excellence[lec_1][1] + "best" + file1[:4] + "~"
                            
    fn = os.path.join(os.path.split(__file__)[0], 'Data_Dumps','TAU',sem[:-1])
    with codecs.open(os.path.join(fn,'KR_Kvutza.txt'), 'r',encoding = 'utf-8') as groups_file:
        groups_file.readline()
        for line in groups_file:
            K_COURSE_NUM, K_KVUTZA_NUM, K_KVUTZA_SEM_YEAR, MISHKAL, COURSE_NAME, FACULTY_NAME, HUG_NAME, KVUTZA_TYPE, OFEN_HORAA, HAVURA, COURSE_LANGUAGE, MATALOT, MATCONET_KVUTZA, VIDEO = line.split('~')
            VIDEO = VIDEO[:-2]
            if K_KVUTZA_SEM_YEAR == sem or (K_KVUTZA_SEM_YEAR[:-1] == sem[:-1] and K_KVUTZA_SEM_YEAR[-1] == u"0"):
                courses_set.add((K_COURSE_NUM,COURSE_NAME))
                if KVUTZA_TYPE == u"ראשית" and main_course.get(K_COURSE_NUM) is None:
                    main_course[K_COURSE_NUM] = K_KVUTZA_NUM
                if KVUTZA_TYPE == u"משנית" and sub_course.get(K_COURSE_NUM) is None:
                    sub_course[K_COURSE_NUM] = K_KVUTZA_NUM
                    
                if HAVURA == " " or HAVURA == u"א":
                    HAVURA = "A"
                if MISHKAL == " ":
                    MISHKAL = "-1"
                if MATCONET_KVUTZA == " ":
                    MATCONET_KVUTZA = "---"
                if OFEN_HORAA == " ":
                    OFEN_HORAA = "---"
                if KVUTZA_TYPE == " ":
                    KVUTZA_TYPE = "---"
                if VIDEO== u"כן":
                    VIDEO = True
                else:
                    VIDEO = False
                if K_KVUTZA_SEM_YEAR[-1] == u"0":
                    isYearly = True
                else:
                    isYearly = False
                faculties_and_hugs.add((FACULTY_NAME,HUG_NAME,K_COURSE_NUM[:4]))
                if num_to_hug.get(K_COURSE_NUM[:4]) is None:
                    num_to_hug[K_COURSE_NUM[:4]] = (FACULTY_NAME,HUG_NAME)
                if complete_semester.get(FACULTY_NAME) is None:
                    complete_semester[FACULTY_NAME] = {HUG_NAME : {K_COURSE_NUM:{'cName': COURSE_NAME,
                        'cNum': K_COURSE_NUM, 
                        'cYear' :  sem[:4],
                        'semester': sem[-1],
                        'isYearly' : isYearly,
                         'faculty': FACULTY_NAME,
                        'depart': HUG_NAME,
                        'zchutHours': MISHKAL,
                        'havurotNum': '1',
                        'hoursNum': 0.0, 
                        'language' : COURSE_LANGUAGE,
                        'matalot' : MATALOT,
                        'video' : VIDEO,
                        'students_ids':[],
                        'kvutzaData': [{'gNum': K_KVUTZA_NUM,
                                        'havura': HAVURA,
                                        'kind': KVUTZA_TYPE,
                                        'ofenHoraa': OFEN_HORAA,
                                        'matconet': MATCONET_KVUTZA,
                                        'days': [],
                                        'beginHours': [],
                                        'endHours': [],
                                        'amountHours' : 0.0,
                                        'lecturer': [],
                                        'excellence' :[],
                                        'place': [],
                                        'moed': [],
                                        'moedType': [],
                                        'startMoedHours':[],
                                        'endMoedHours':[],
                                        'dates':[]
                                        }]
                        }}}
                else:
                    if complete_semester[FACULTY_NAME].get(HUG_NAME) is None:
                        complete_semester[FACULTY_NAME][HUG_NAME] = {K_COURSE_NUM:{'cName': COURSE_NAME,
                        'cNum': K_COURSE_NUM, 
                        'cYear' :  sem[:4],
                        'semester': sem[-1],
                        'isYearly' : isYearly,
                         'faculty': FACULTY_NAME,
                        'depart': HUG_NAME,
                        'zchutHours': MISHKAL,
                        'havurotNum': '1',
                        'hoursNum': 0.0, 
                        'language' : COURSE_LANGUAGE,
                        'matalot' : MATALOT,
                        'video' : VIDEO,
                        'students_ids':[],
                        'kvutzaData': [{'gNum': K_KVUTZA_NUM,
                                        'havura': HAVURA,
                                        'kind': KVUTZA_TYPE,
                                        'ofenHoraa': OFEN_HORAA,
                                        'matconet': MATCONET_KVUTZA,
                                        'days': [],
                                        'beginHours': [],
                                        'endHours': [],
                                        'amountHours' : 0.0,
                                        'lecturer': [],
                                        'excellence' :[],
                                        'place': [],
                                        'moed': [],
                                        'moedType': [],
                                        'startMoedHours':[],
                                        'endMoedHours':[],
                                        'dates':[]
                                        }]
                        }}
                    
                    else:
                        if complete_semester[FACULTY_NAME][HUG_NAME].get(K_COURSE_NUM) is None:
                            complete_semester[FACULTY_NAME][HUG_NAME][K_COURSE_NUM] = {'cName': COURSE_NAME,
                        'cNum': K_COURSE_NUM, 
                        'cYear' :  sem[:4],
                        'semester': sem[-1],
                        'isYearly' : isYearly,
                         'faculty': FACULTY_NAME,
                        'depart': HUG_NAME,
                        'zchutHours': MISHKAL,
                        'havurotNum': '1',
                        'hoursNum': 0.0, 
                        'language' : COURSE_LANGUAGE,
                        'matalot' : MATALOT,
                        'video' : VIDEO,
                        'students_ids':[],
                        'kvutzaData': [{'gNum': K_KVUTZA_NUM,
                                        'havura': HAVURA,
                                        'kind': KVUTZA_TYPE,
                                        'ofenHoraa': OFEN_HORAA,
                                        'matconet': MATCONET_KVUTZA,
                                        'days': [],
                                        'beginHours': [],
                                        'endHours': [],
                                        'amountHours' : 0.0,
                                        'lecturer': [],
                                        'excellence' :[],
                                        'place': [],
                                        'moed': [],
                                        'moedType': [],
                                        'startMoedHours':[],
                                        'endMoedHours':[],
                                        'dates':[]
                                        }]
                        }
                        else:
                            if HAVURA not in [elem['havura'] for elem in complete_semester[FACULTY_NAME][HUG_NAME][K_COURSE_NUM]['kvutzaData']]:
                                complete_semester[FACULTY_NAME][HUG_NAME][K_COURSE_NUM]['havurotNum'] = str(int(complete_semester[FACULTY_NAME][HUG_NAME][K_COURSE_NUM]['havurotNum']) + 1) 
                            complete_semester[FACULTY_NAME][HUG_NAME][K_COURSE_NUM]['kvutzaData'].append({'gNum': K_KVUTZA_NUM,
                                        'havura': HAVURA,
                                        'kind': KVUTZA_TYPE,
                                        'ofenHoraa': OFEN_HORAA,
                                        'matconet': MATCONET_KVUTZA,
                                        'days': [],
                                        'beginHours': [],
                                        'endHours': [],
                                        'amountHours' : 0.0,
                                        'lecturer': [],
                                        'excellence' :[],
                                        'place': [],
                                        'moed': [],
                                        'moedType': [],
                                        'startMoedHours':[],
                                        'endMoedHours':[],
                                        'dates':[]
                                        })
    with codecs.open(os.path.join(fn,'KR_Kvutza_Zamak.txt'), 'r',encoding = 'utf-8') as mifgash_file:
        mifgash_file.readline()
        for line in mifgash_file: 
            K_COURSE_NUM,K_KVUTZA_NUM,K_KVUTZA_SEM_YEAR,YOM,ME_SHAA,AD_SHAA,LECTURE_NAME,BINYAN,CHEDER = line.split('~')
            CHEDER = CHEDER[:-2]
            if K_KVUTZA_SEM_YEAR == sem or (K_KVUTZA_SEM_YEAR[:-1] == sem[:-1] and K_KVUTZA_SEM_YEAR[-1] == u"0"):
                
                ME_SHAA = format_hour(ME_SHAA)
                AD_SHAA = format_hour(AD_SHAA)
                if YOM == " ":
                    YOM = "---"
                if LECTURE_NAME == " ":
                    LECTURE_NAME = "---"
                if BINYAN == " ":
                    PLACE = "---"
                if CHEDER == " ":
                    PLACE = BINYAN
                else:
                    PLACE = BINYAN + u" " + CHEDER
                
                if LECTURE_NAME != "---":
                    lecturers.add(LECTURE_NAME)
                try:
                    curr_facu = num_to_hug[K_COURSE_NUM[:4]][0]
                    curr_hug = num_to_hug[K_COURSE_NUM[:4]][1]
                except KeyError:
                    continue
                for group in complete_semester[curr_facu][curr_hug][K_COURSE_NUM]['kvutzaData'] :
                    if group['gNum'] == K_KVUTZA_NUM:
                        already_added = False
                        i = 0
                        while i < len(group['days']):
                            if  group['days'][i] == YOM and group['beginHours'][i] == ME_SHAA and group['endHours'][i] == AD_SHAA and not group['lecturer'][i] == LECTURE_NAME:
                                group['lecturer'][i] = group['lecturer'][i] + u"/" + LECTURE_NAME
                                already_added = True
                            i = i+1
                        if not already_added:
                            group['days'].append(YOM)
                            group['beginHours'].append(ME_SHAA)
                            group['endHours'].append(AD_SHAA)
                            group['lecturer'].append(LECTURE_NAME)
                            
                            excellence_string = excellence.get(LECTURE_NAME)
                            if excellence_string is None:
                                group['excellence'].append("")
                            else:
                                group['excellence'].append((excellence_string[0] + excellence_string[1])[:-1])
                           
                            
                            group['place'].append(PLACE)
                            
                            if not ME_SHAA == "---" and not AD_SHAA == "---":
                                try:
                                    hours = ((datetime.datetime.strptime(AD_SHAA,'%H:%M') - datetime.datetime.strptime(ME_SHAA,'%H:%M')).total_seconds()/60/60)
                                    group['amountHours'] = group['amountHours'] + hours
                                    if main_course.get(K_COURSE_NUM) == K_KVUTZA_NUM or sub_course.get(K_COURSE_NUM) == K_KVUTZA_NUM:
                                        complete_semester[curr_facu][curr_hug][K_COURSE_NUM]['hoursNum'] = complete_semester[curr_facu][curr_hug][K_COURSE_NUM]['hoursNum'] + hours
                                except UnicodeEncodeError:
                                    continue
                                     
    with codecs.open(os.path.join(fn,'KR_Kvutza_Moed.txt'), 'r',encoding = 'utf-8') as mivhan_file:
        mivhan_file.readline()
        for line in mivhan_file: 
            K_COURSE_NUM,K_KVUTZA_NUM,K_KVUTZA_SEM_YEAR,K_MOED,K_MOED_TYPE,ME_SHAA,AD_SHAA,MOED_DATE = line.split('~')
            MOED_DATE = MOED_DATE[:-2]
            if K_KVUTZA_SEM_YEAR == sem or (K_KVUTZA_SEM_YEAR[:-1] == sem[:-1] and K_KVUTZA_SEM_YEAR[-1] == u"0"):
                if K_MOED == " ":
                    K_MOED = "---"
                if K_MOED_TYPE == " ":
                    K_MOED_TYPE = "---"
                ME_SHAA = format_hour(ME_SHAA)
                AD_SHAA = format_hour(AD_SHAA)
                if MOED_DATE == " ":
                    MOED_DATE = "---"

                try:
                    curr_facu = num_to_hug[K_COURSE_NUM[:4]][0]
                    curr_hug = num_to_hug[K_COURSE_NUM[:4]][1]
                except KeyError:
                    continue
                for group in complete_semester[curr_facu][curr_hug][K_COURSE_NUM]['kvutzaData'] :
                    if group['gNum'] == K_KVUTZA_NUM:
                        group['moed'].append(K_MOED)
                        group['moedType'].append(K_MOED_TYPE)
                        group['startMoedHours'].append(ME_SHAA)
                        group['endMoedHours'].append(AD_SHAA)
                        group['dates'].append(MOED_DATE)

    fn1 = os.path.join(os.path.split(__file__)[0], 'Data_Dumps','TAU')
    with codecs.open(os.path.join(fn1,'lec-2009.txt'), 'r',encoding = 'utf-8') as lec_file_2009:
        course_to_lec['2009'] = {}
        for line in lec_file_2009: 
            COURSE, LECTURER = line.split('~')
            course_to_lec['2009'][COURSE] = LECTURER
    with codecs.open(os.path.join(fn1,'lec-2010.txt'), 'r',encoding = 'utf-8') as lec_file_2010:
        course_to_lec['2010'] = {}
        for line in lec_file_2010: 
            COURSE, LECTURER = line.split('~')
            course_to_lec['2010'][COURSE] = LECTURER
    with codecs.open(os.path.join(fn1,'lec-2011.txt'), 'r',encoding = 'utf-8') as lec_file_2011:
        course_to_lec['2011'] = {}
        for line in lec_file_2011: 
            COURSE, LECTURER = line.split('~')
            course_to_lec['2011'][COURSE] = LECTURER
    with codecs.open(os.path.join(fn1,'lec-2012.txt'), 'r',encoding = 'utf-8') as lec_file_2012:
        course_to_lec['2012'] = {}
        for line in lec_file_2012: 
            COURSE, LECTURER = line.split('~')
            course_to_lec['2012'][COURSE] = LECTURER


    fn2 = os.path.join(os.path.split(__file__)[0], 'Data_Dumps','TAU','Bid')                
    with codecs.open(os.path.join(fn2,'BD_Stats.txt'), 'r',encoding = 'utf-8') as BD_file:
        BD_file.readline()
        for line in BD_file: 
            K_FACBIDD,K_MIKTZE,K_COURSE_NUM,K_KVUTZA_NUM,K_KVUTZA_SEM_YEAR, PLACES,REQUESTED,ACCEPTED,REJECTED,REJECTED_NETO,MAX_POINTS,MIN_ACCEPT_POINTS  = line.split('~')
            if K_MIKTZE != '1':
                continue
            MIN_ACCEPT_POINTS = MIN_ACCEPT_POINTS[:-2]
            if K_KVUTZA_NUM == "  ":
                K_KVUTZA_NUM = "00"
            if PLACES == "":
                PLACES = "-1"
            if REQUESTED == "":
                REQUESTED = "-1"
            if ACCEPTED == "":
                ACCEPTED = "-1"
            if REJECTED == "":
                REJECTED = "-1"
            if REJECTED_NETO == "":
                REJECTED_NETO = "-1"
            if MAX_POINTS == "":
                MAX_POINTS = "-1"
            if MIN_ACCEPT_POINTS == "":
                MIN_ACCEPT_POINTS = "-1"
            
            if course_to_lec.get(K_KVUTZA_SEM_YEAR[:-1]).get(K_COURSE_NUM +"-"+ K_KVUTZA_NUM) is None:
                LECTURER = " "
            else:
                LECTURER = course_to_lec.get(K_KVUTZA_SEM_YEAR[:-1]).get(K_COURSE_NUM +"-"+ K_KVUTZA_NUM)
            isMain = False
            try:
                curr_facu = num_to_hug[K_COURSE_NUM[:4]][0]
                curr_hug = num_to_hug[K_COURSE_NUM[:4]][1]
            except KeyError:
                continue
            
            if complete_semester_bid.get(curr_facu) is None:
                complete_semester_bid[curr_facu] = {curr_hug:{K_COURSE_NUM:{K_KVUTZA_SEM_YEAR : {K_MIKTZE: [{'gNum' : K_KVUTZA_NUM,
                                                                        'lecturer' : LECTURER,
                                                                        'places' : PLACES,
                                                                        'isMain' :  isMain,
                                                                         'requested' : REQUESTED,
                                                                         'accepted' : ACCEPTED,
                                                                         'rejected' : REJECTED,
                                                                         'rejected_neto' : REJECTED_NETO,
                                                                         'max_points' : MAX_POINTS,
                                                                         'min_accept_points' : MIN_ACCEPT_POINTS}
                                                                        ]}}}}
            else:
                if complete_semester_bid[curr_facu].get(curr_hug) is None:
                    complete_semester_bid[curr_facu][curr_hug] = {K_COURSE_NUM:{K_KVUTZA_SEM_YEAR : {K_MIKTZE: [{'gNum' : K_KVUTZA_NUM,
                                                                        'lecturer' : LECTURER,
                                                                        'places' : PLACES,
                                                                        'isMain' :  isMain,
                                                                         'requested' : REQUESTED,
                                                                         'accepted' : ACCEPTED,
                                                                         'rejected' : REJECTED,
                                                                         'rejected_neto' : REJECTED_NETO,
                                                                         'max_points' : MAX_POINTS,
                                                                         'min_accept_points' : MIN_ACCEPT_POINTS}
                                                                        ]}}}
                else:
                    if complete_semester_bid[curr_facu][curr_hug].get(K_COURSE_NUM) is None:
                        complete_semester_bid[curr_facu][curr_hug][K_COURSE_NUM] = {K_KVUTZA_SEM_YEAR : {K_MIKTZE: [{'gNum' : K_KVUTZA_NUM,
                                                                        'lecturer' : LECTURER,
                                                                        'places' : PLACES,
                                                                        'isMain' :  isMain,
                                                                         'requested' : REQUESTED,
                                                                         'accepted' : ACCEPTED,
                                                                         'rejected' : REJECTED,
                                                                         'rejected_neto' : REJECTED_NETO,
                                                                         'max_points' : MAX_POINTS,
                                                                         'min_accept_points' : MIN_ACCEPT_POINTS}
                                                                        ]}}
                    else:
                        if complete_semester_bid[curr_facu][curr_hug][K_COURSE_NUM].get(K_KVUTZA_SEM_YEAR) is None:
                            complete_semester_bid[curr_facu][curr_hug][K_COURSE_NUM][K_KVUTZA_SEM_YEAR] = {K_MIKTZE: [{'gNum' : K_KVUTZA_NUM,
                                                                        'lecturer' : LECTURER,
                                                                        'places' : PLACES,
                                                                        'isMain' :  isMain,
                                                                         'requested' : REQUESTED,
                                                                         'accepted' : ACCEPTED,
                                                                         'rejected' : REJECTED,
                                                                         'rejected_neto' : REJECTED_NETO,
                                                                         'max_points' : MAX_POINTS,
                                                                         'min_accept_points' : MIN_ACCEPT_POINTS}
                                                                        ]}
                        else:
                            if complete_semester_bid[curr_facu][curr_hug][K_COURSE_NUM][K_KVUTZA_SEM_YEAR].get(K_MIKTZE) is None:
                                complete_semester_bid[curr_facu][curr_hug][K_COURSE_NUM][K_KVUTZA_SEM_YEAR][K_MIKTZE] = [{'gNum' : K_KVUTZA_NUM,
                                                                        'lecturer' : LECTURER,
                                                                        'places' : PLACES,
                                                                        'isMain' :  isMain,
                                                                         'requested' : REQUESTED,
                                                                         'accepted' : ACCEPTED,
                                                                         'rejected' : REJECTED,
                                                                         'rejected_neto' : REJECTED_NETO,
                                                                         'max_points' : MAX_POINTS,
                                                                         'min_accept_points' : MIN_ACCEPT_POINTS}
                                                                        ]
                            else:
                                complete_semester_bid[curr_facu][curr_hug][K_COURSE_NUM][K_KVUTZA_SEM_YEAR][K_MIKTZE].append({'gNum' : K_KVUTZA_NUM,
                                                                        'lecturer' : LECTURER,
                                                                        'places' : PLACES,
                                                                        'isMain' :  isMain,
                                                                         'requested' : REQUESTED,
                                                                         'accepted' : ACCEPTED,
                                                                         'rejected' : REJECTED,
                                                                         'rejected_neto' : REJECTED_NETO,
                                                                         'max_points' : MAX_POINTS,
                                                                         'min_accept_points' : MIN_ACCEPT_POINTS})
    course_list = []                                                                
    for course_elem in courses_set:
        course_list.append({"courseCode" : course_elem[0], "courseName": course_elem[1] +" (" + course_elem[0] +")"})
    course_list.sort(key = lambda x : x['courseName'])
    
    fac_map={}
    for fac in faculties_and_hugs:
        if fac_map.get(fac[0]) is None:
            fac_map[fac[0]] = [{'dNum': fac[2],'dName': fac[1]}]
        else:
            fac_map.get(fac[0]).append({'dNum': fac[2],'dName': fac[1]})
    
    faculties = []
    j = 1
    for fac,hugim in fac_map.items():
        faculties.append({'fNum': str(j),'fName': fac,'fDeparts': hugim})
        j = j+1
    faculties.sort(key = lambda x : x['fName'])
    return (complete_semester,   list(faculties_and_hugs),    list(lecturers),   sem,    uni,    course_list,complete_semester_bid, faculties)

def exporter(x):
    univ = n_University.get_by_id(id = x[4])
    if univ is None:
        univ = n_University(id = x[4],uni_name = x[4])
    univ.faculties_and_hugs[x[3]] = x[7]
    univ_key = univ.put()
    
    
    
    j = 0 # CHANGE HERE!FOR REQUEST TO BIG!
    
    while j < len(x[1]):
        fac_and_hug = x[1][j]
        hug = n_Hug(id = 'hug_'+fac_and_hug[2]+'_'+x[3],semester = x[3],hug_num= fac_and_hug[2] ,fac_name = fac_and_hug[0],hug_name = fac_and_hug[1], stats = x[0][fac_and_hug[0]][fac_and_hug[1]],parent = univ_key)
        hug.put()
        logging.error(x[3] + " hug " + str(j))
        try:
            hug_bid = n_Hug_bid(id = 'hugbid_'+fac_and_hug[2], hug_num= fac_and_hug[2] ,fac_name = fac_and_hug[0],hug_name = fac_and_hug[1], bid = x[6][fac_and_hug[0]][fac_and_hug[1]],parent = univ_key)
            hug_bid.put()
            logging.error(x[3] + " hug bid " + str(j))
        except KeyError:
            logging.error(fac_and_hug[0] + " or " + fac_and_hug[1] +" not found")
        
        j =j+1
        

   

        
    semester_ent = n_Semester(id = "sem" + x[3], semester = x[3], courses_list = x[5],parent = univ_key)
    semester_ent.put()


def facebook_cleaner(user):
    stats_updater(user, 'semstats20151', 0)
    stats_updater(user, 'semstats20152', 1)

@ndb.transactional(retries=1000000)
def stats_updater(user,identifier,i):
    sem = ndb.Key('n_University','TAU','n_Courses_stats',identifier).get()
    coursesList = user.chosenCoursesLists.get(identifier[8:-1])
    if coursesList is None: return
    
    for course in coursesList[i]:
        if sem.stats.get(course) is None:
            sem.stats[course] = [user.userId]
        elif not user.userId in sem.stats.get(course):
            sem.stats.get(course).append(user.userId)
    sem.put()
    
#def chosen_courses_fixer(user):
 #   user.chosenCoursesLists =  {"2015": user.chosenCoursesLists}
  #  yield op.db.Put(user)
    
    
if __name__ == '__main__':
    importer()